package org.dromara.hotel.controller;

import java.util.List;

import lombok.RequiredArgsConstructor;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.validation.constraints.*;
import cn.dev33.satoken.annotation.SaCheckPermission;
import org.dromara.hotel.domain.bo.PriceCalendarDTO;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import org.dromara.common.idempotent.annotation.RepeatSubmit;
import org.dromara.common.log.annotation.Log;
import org.dromara.common.web.core.BaseController;
import org.dromara.common.mybatis.core.page.PageQuery;
import org.dromara.common.core.domain.R;
import org.dromara.common.core.validate.AddGroup;
import org.dromara.common.core.validate.EditGroup;
import org.dromara.common.log.enums.BusinessType;
import org.dromara.common.excel.utils.ExcelUtil;
import org.dromara.hotel.domain.vo.TerPriceCalendarVo;
import org.dromara.hotel.domain.bo.TerPriceCalendarBo;
import org.dromara.hotel.service.ITerPriceCalendarService;
import org.dromara.common.mybatis.core.page.TableDataInfo;

/**
 * 酒店日历价格
 * 前端访问路由地址为:/hotel/priceCalendar
 *
 * @author xch
 * @date 2025-06-10
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/priceCalendar")
public class TerPriceCalendarController extends BaseController {

    private final ITerPriceCalendarService terPriceCalendarService;

    /**
     * 查询酒店日历价格列表
     */
    @SaCheckPermission("hotel:priceCalendar:list")
    @GetMapping("/list")
    public TableDataInfo<TerPriceCalendarVo> list(TerPriceCalendarBo bo, PageQuery pageQuery) {
        return terPriceCalendarService.queryPageList(bo, pageQuery);
    }
    @GetMapping("/wechat/queryTotalPrice")
    public R<Integer> queryTotalPrice( TerPriceCalendarBo bo) {
        return R.ok(terPriceCalendarService.queryTotalPrice(bo));
    }
    @GetMapping("/wechat")
    public R<List<TerPriceCalendarVo>> queryCalendar(TerPriceCalendarBo bo) {
        return R.ok(terPriceCalendarService.queryList(bo));
    }

    /**
     * 导出酒店日历价格列表
     */
    @SaCheckPermission("hotel:priceCalendar:export")
    @Log(title = "酒店日历价格", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(TerPriceCalendarBo bo, HttpServletResponse response) {
        List<TerPriceCalendarVo> list = terPriceCalendarService.queryList(bo);
        ExcelUtil.exportExcel(list, "酒店日历价格", TerPriceCalendarVo.class, response);
    }

    /**
     * 获取酒店日历价格详细信息
     *
     * @param id 主键
     */
    @SaCheckPermission("hotel:priceCalendar:query")
    @GetMapping("/{id}")
    public R<TerPriceCalendarVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable("id") Long id) {
        return R.ok(terPriceCalendarService.queryById(id));
    }

    /**
     * 新增酒店日历价格
     */
    @SaCheckPermission("hotel:priceCalendar:add")
    @Log(title = "酒店日历价格", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody TerPriceCalendarBo bo) {
        return toAjax(terPriceCalendarService.insertByBo(bo));
    }
    @PostMapping("/inventoryModify")
    public R<Void> inventoryModify(@Validated(AddGroup.class) @RequestBody PriceCalendarDTO dto) {
        return toAjax(terPriceCalendarService.inventoryModify(dto));
    }
    /**
     * 修改酒店日历价格
     */
    @SaCheckPermission("hotel:priceCalendar:edit")
    @Log(title = "酒店日历价格", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody TerPriceCalendarBo bo) {
        return toAjax(terPriceCalendarService.updateByBo(bo));
    }

    /**
     * 删除酒店日历价格
     *
     * @param ids 主键串
     */
    @SaCheckPermission("hotel:priceCalendar:remove")
    @Log(title = "酒店日历价格", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable("ids") Long[] ids) {
        return toAjax(terPriceCalendarService.deleteWithValidByIds(List.of(ids), true));
    }
}
